<?php 
$this->Html->script('theme/cats',false);

$CATS=ClassRegistry::init('Category')->getCats();

$selected_cat=isset($this->params['pass'][0])? $this->params['pass'][0] : 0;

?>
	<h3><?php __('Categories'); ?></h3>
   	<ul id="catsli">
<?
foreach ($CATS as $_cat){
	$_expand=false;
	$_subcats='';

	foreach ($_cat['Children'] as $_child){
		$_ops=array();
		if($_child['id']==$selected_cat){
			$_expand=true;
			$_ops+=array('style'=>'background:none repeat scroll 0 0 #F0F09A');
		}
		
		$_subcats.=$this->Html->tag('li', $this->Html->link($_child['name'],array('slug'=>Inflector::slug($_child['name']),$_child['id']),$_ops+array('escape'=>'ISO-8859-1')));
	}

	if($_cat['Category']['id']==$selected_cat){
		$_expand=true;
	}
	?>
	<li>
	  <div<?=($_expand)? ' style="background:none repeat scroll 0 0 #F0F09A"':'' ?>>
	    <a class="expand-cat" style="cursor:pointer"><?=($_expand)? '-' : '+' ?></a>
		<?=$this->Html->link($_cat['Category']['name'],array('slug'=>Inflector::slug($_cat['Category']['name']),$_cat['Category']['id']),array('escape'=>'ISO-8859-1')) ?>
	  </div>
		<?
		$_ops=array('class'=>'subcatsli');
		if($_expand) $_ops+=array('style'=>'display:block');
		
		echo $this->Html->tag('ul',$_subcats,$_ops);
		?>
	</li>		
<?php 
}
?>
	</ul>